package contegor.scire.core;

import java.io.Serializable;

/**
 * Base class for {@link IdFragment}s that are based on numbers.
 * 
 * @version $Revision$ 
 * @author  Héctor Cirbián Pousa ($Author$)
 */
public abstract class NumericIdFragment implements IdFragment, Serializable{
  private static final long serialVersionUID = 7690188497746058879L;

  @Override
  public int compareTo(IdFragment obj) {
    if (this == obj)
      return 0;
    if (!(obj instanceof NumericIdFragment))
      return this.toString().compareTo(obj.toString());
    else
      return Double.compare(this.getNumber().doubleValue(), ((NumericIdFragment)obj).getNumber().doubleValue());
  }

  @Override
  public boolean equals(Object obj) {
    if (obj instanceof IdFragment)
      return this.compareTo((IdFragment)obj) == 0;
    else
      return false;
  }

  public abstract Number getNumber();
}
